﻿Public Class DiagramDisplay
    Public Event NameChanged(ByVal Name As String)
    Public Event ToggleGrid()
    Public Event NewGridColor(ByVal NewColor As System.Drawing.Color)
    Public Event OpenFile()
    Public Event SaveFile()
    Public Event SaveAsFile()
    Public Event Clear()
    Public Event SetMode(ByVal Mode As EditMode)
    Public Event NewBackgroundColor(ByVal NewColor As System.Drawing.Color)

    Private M_DiagramName As String
    Private M_Mode As EditMode = EditMode.UnLocked
    Private M_BackColor As System.Drawing.Color = Drawing.Color.Silver
    Private M_GridColor As System.Drawing.Color = Drawing.Color.Black

    Public Enum EditMode
        Locked = 0
        UnLocked = 1
    End Enum
    Public Property DiagramName() As String
        Get
            Return M_DiagramName
        End Get
        Set(ByVal value As String)
            M_DiagramName = value
            UpdateMe()
        End Set
    End Property

    Public Property Mode() As EditMode
        Get
            Return M_Mode
        End Get
        Set(ByVal value As EditMode)
            M_Mode = value
            UpdateMe()
        End Set
    End Property
    Public Property BackgroundColor() As System.Drawing.Color
        Get
            Return M_BackColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            M_BackColor = value
            UpdateMe()
        End Set
    End Property
    Public Property GridColor() As System.Drawing.Color
        Get
            Return M_GridColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            M_GridColor = value
            UpdateMe()
        End Set
    End Property

    Private Sub UpdateMe()

        If M_Mode = EditMode.UnLocked Then
            'Edit Mode
            ToolStripLabel2.Text = "Mode : Unlocked"

            'Diagram Name
            ToolStripTextBox1.Text = M_DiagramName
            ToolStripLabel4.Text = M_DiagramName
            ToolStripLabel1.Visible = True
            ToolStripTextBox1.Visible = True
            ToolStripButton1.Visible = True
            ToolStripLabel4.Visible = False

            'Grid Color
            ToolStripColorPicker1.Color = M_GridColor

            'Back Color
            ToolStripColorPicker2.Color = M_BackColor

        Else
            'Edit Mode
            ToolStripLabel2.Text = "Mode : Locked"

            'Diagram Name
            ToolStripTextBox1.Text = M_DiagramName
            ToolStripLabel4.Text = M_DiagramName
            ToolStripLabel1.Visible = False
            ToolStripTextBox1.Visible = False
            ToolStripButton1.Visible = False
            ToolStripLabel4.Visible = True

            'Grid Color
            ToolStripColorPicker1.Color = M_GridColor

            'Back Color
            ToolStripColorPicker2.Color = M_BackColor

        End If

    End Sub
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        If M_DiagramName <> ToolStripTextBox1.Text Then
            RaiseEvent NameChanged(ToolStripTextBox1.Text)
        End If
        M_DiagramName = ToolStripTextBox1.Text
        UpdateMe()
    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        M_Mode = EditMode.UnLocked
        UpdateMe()
        RaiseEvent SetMode(EditMode.UnLocked)
    End Sub

    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        M_Mode = EditMode.Locked
        UpdateMe()
        RaiseEvent SetMode(EditMode.Locked)
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        RaiseEvent ToggleGrid()
    End Sub

    Private Sub ToolStripColorPicker1_SelectedColorChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripColorPicker1.SelectedColorChanged
        M_GridColor = ToolStripColorPicker1.Color
        RaiseEvent NewGridColor(ToolStripColorPicker1.Color)
    End Sub

    Private Sub NewToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripButton.Click
        RaiseEvent Clear()
    End Sub

    Private Sub OpenToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripButton.Click
        RaiseEvent OpenFile()
    End Sub

    Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
        RaiseEvent SaveFile()
    End Sub

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
    End Sub

    Private Sub ToolStripColorPicker2_SelectedColorChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripColorPicker2.SelectedColorChanged
        M_BackColor = ToolStripColorPicker2.Color
        RaiseEvent NewBackgroundColor(ToolStripColorPicker2.Color)
    End Sub

End Class
